package com.cssw.fyzb.tps.config.pay;

import com.ijpay.wxpay.WxPayApiConfig;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @Author: chenchao
 */
@Component
@Setter
@Getter
public class WxPay {

    @Value("${config.wx.value.appId}")
    private String appId;

    @Value("${config.wx.value.mchId}")
    private String mchId;

    @Value("${config.wx.value.subMchId}")
    private String subMchId;

    @Value("${config.wx.value.subAppId}")
    private String subAppId;

    @Value("${config.wx.value.apiKey}")
    private String apiKey;

    private String certPath;

    @Value("${config.wx.value.domain}")
    private String domain;

    @Value("${config.wx.value.notifyUrl}")
    private String notifyUrl;

    private WxPayApiConfig apiConfig;

    public WxPayApiConfig getApiConfig() {
        if (apiConfig == null) {
            synchronized (WxPayApiConfig.class) {
                if (apiConfig == null) {
                    apiConfig = WxPayApiConfig.builder()
                            .appId(subAppId)
                            .mchId(subMchId)
                            .slAppId(appId)
                            .slMchId(mchId)
                            .apiKey(apiKey)
                            .certPath(certPath)
                            .domain(domain)
                            .build();
                }
            }
        }
        return apiConfig;
    }

}
